<?php
namespace Home\Model;
use Think\Model;
/**
* 
*/
class MoneyLogModel extends CommonModel{
	/**
     * 用户取消活动，还没有人报名，则吧红包全部返还给发起人
     * @access public
     * @param int $user_id 用户id
     * @param decimal $sum 返还的红包总金额
     * @param int $id 活动id
     * @param string $content 说明
     */
	public function addCancelActiviMoneyLog($user_id,$sum,$id,$content=""){
		$moneyArray = array(
			'user_id' => $user_id,
			'money'  => $sum,
			'add_time' => time(),
			'type'   => 107,
			'pay_type' => 3,
			'activity_id' => $id,
		);
		if($content){
			$moneyArray['content'] = $content;
		}else{
			$moneyArray['content'] = '取消活动退回红包';
		}
		$res = M('money_log')->add($moneyArray);
		return $res ? true : false;
	}
	/**
     * 发布者取消活动，有用户报名还未邀约，则退回给他见面礼
     * @access public
     * @param int $user_id 用户id
     * @param decimal $gift 见面礼金额
     * @param int $id 活动id
     * @param string $content 说明
     */
	public function addCancelActiviGiftLog($user_id,$gift,$id,$content=""){
		$moneyArray = array(
			'user_id' => $user_id,
			'money'  => $gift,
			'add_time' => time(),
			'type'   => 107,
			'activity_id' => $id,
		);
		if($content){
			$moneyArray['content'] = $content;
		}else{
			$moneyArray['content'] = '取消活动退回红包';
		}
		$res = M('money_log')->add($moneyArray);
		return $res ? true : false;
	}

	/**
     * 发布者取消活动，有用户报名还未邀约，未发完的红包给平台
     * @access public
     * @param int $user_id 用户id
     * @param decimal $sum 返还的红包总金额
     * @param int $id 活动id
     * @param string $content 说明
     */
	public function addAbolishPlatFormLog($user_id,$red_money,$id,$content=""){
		$moneyArray = array(
			'user_id' => $user_id,
			'money'  => $red_money,
			'add_time' => time(),
			'activity_id' => $id,
		);
		if($content){
			$moneyArray['content'] = $content;
		}else{
			$moneyArray['content'] = '取消活动扣留红包';
		}
		$res = M('platform_redlog')->add($moneyArray);
		return $res ? true : false;
	}
	/**
     * 发布者爽约，但是用户没有爽约，将一般见面礼作为诚意金支付给参与者，并返回剩下的一半给发起人
     * @access public
     * @param int $user_id 用户id
     * @param decimal $sum 返还的红包总金额
     * @param int $id 活动id
     * @param string $content 说明
     */
	public function addFailjoinChengyijing($id,$user_id,$activi_user,$money){
		$moneyArray[] = array(
			'user_id' => $user_id,
			'money'  => $money,
			'add_time' => time(),
			'activity_id' => $id,
			'type'		=> 109,
			'content'	=> '发起者爽约支付诚意金',
			'pay_type'	=> 3,
		);
		$moneyArray[] = array(
			'user_id' => $activi_user,
			'money'  => $money,
			'add_time' => time(),
			'activity_id' => $id,
			'type'		=> 105,
			'content'	=> '发起者爽约退回一半的见面礼',
			'pay_type'	=> 3,
		);
		M('money_log')->add($moneyArray);
		M('user')->where(array('id'=>$user_id))->setInc('money',$money);
		$res = M('user')->where(array('id'=>$activi_user))->setInc('money',$money);
		if($res === false){
			return false;
		}
		return true;
	}
	
}